package com.foreknow.Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

/**
 * 1.list集合：有序、可重复
 * 2.set集合：无序、不可重复
 */
public class CollectionDemo03 {
    public static void main(String[] args) {
        //创建集合对象
        Collection collection = new ArrayList();
        Collection c2 = new HashSet();
        //添加元素
        collection.add(1);
        collection.add(2);
        collection.add(3);
        collection.add(4);
        collection.add(5);
        collection.add(5);
        //获取迭代器对象
        Iterator it = collection.iterator();
        //迭代集合
        while (it.hasNext()){
            Object object = it.next();
            if (object instanceof  Integer){
                System.out.println("Integer类型");
            }
            System.out.println(object);//println会调用toString方法
        }

        c2.add(100);
        c2.add(300);
        c2.add(400);
        c2.add(600);
        c2.add(400);
        Iterator it2 = c2.iterator();
        while (it2.hasNext()){
            Object object2 = it2.next();
            System.out.println(object2);
        }
    }
}
